package procsim;

public class Inverter implements Element {
    private Signal inSig, result;

    public Inverter(Signal in){
        if(in!=null) in.addElement(this);
        inSig=in;
    }
    public Inverter(Signal in, Signal out){
        if(in!=null) in.addElement(this);
        inSig=in;
        result=out;
    }
    @Override
    public Signal result() {
        return result;
    }
    public Inverter setResult(Signal sig){
        result=sig;
        return this;
    }
    @Override
    public Inverter tick() {
        if(result!=null) result.set(inSig.negate());
        return this;
    }
    @Override
    public void updateSignal(Sig sig) {
        if(inSig!=null && inSig==sig){
            inSig.set(sig.get(), false);
            tick();
        }
    }

}
